package com.fcmeditech.AsianSexyGirls;

import java.util.ArrayList;

import com.fcmeditech.AsianSexyGirls.File.ImageLoaderDefault;
import com.fcmeditech.AsianSexyGirls.File.ImageLoaderGrid;



import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class Gridadapter extends BaseAdapter{
	 private Context context;
	// public ImageLoaderGrid imageLoader; 
	 public ImageLoaderDefault imageLoader;
	 private ArrayList<ImageObject> listimg;
	 
	 
	
	public Gridadapter(Context c, ArrayList<ImageObject> _listimg) {
		super();
		this.context=c;
		this.listimg = _listimg;
	    imageLoader=new ImageLoaderDefault(c);
	}


	public int getCount() {
		// TODO Auto-generated method stub
		return listimg.size();
	}



	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}



	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}



	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
			View vi=convertView;
			GridHolder holder=null;
			final ImageObject myImg= listimg.get(position);
			//int N=listimg.size();
			//imageSelection=new boolean[N];

	        if(convertView==null){
	        	LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	        	vi = inflater.inflate(R.layout.gridimage2, parent, false);
	        	holder =new GridHolder();
	        	
	        	holder.imageview=(ImageView)vi.findViewById(R.id.imageDisplayGrid2);
	        	holder.checkbox=(CheckBox)vi.findViewById(R.id.imageGridCheck);
	        	
	        	vi.setTag(holder);
	        }
	        else holder=(GridHolder)vi.getTag();
	        ///set data to Grid Item
	        
	        holder.id=position;
	        //holder.checkbox.setChecked(imageSelection[position]);
	        if(ImageObject.status) holder.checkbox.setVisibility(View.VISIBLE);
	        else holder.checkbox.setVisibility(View.INVISIBLE);
	        
	        holder.checkbox.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					//Toast.makeText(context, myImg.getmNameImg(), Toast.LENGTH_SHORT).show();
					
					//update status of checkboxes
					boolean new_status=myImg.getCheckStatus();
					if(new_status) new_status=false;
					else new_status=true;
					listimg.get(position).setCheckStatus(new_status);
				}
        		
        	});
	        
	        holder.imageview.setImageBitmap(myImg.getmImage());
	        holder.checkbox.setChecked(listimg.get(position).getCheckStatus());
	        
	       // RelativeLayout layout = (RelativeLayout) vi.findViewById(R.id.llProgressBarGrid);
	       //	        imageLoader.putUrl(image, activity, myImg.getImgLink());
	       
	       // imageLoader.DisplayImage(myImg.getImgLink(), activity, image,layout);
	       // myImg.setmImage(imageLoader.GetImage(myImg.getImgLink(), activity, image));
	       // imageLoader.DisplayImage(myImg.getImgLink(), image);
		return vi;
		
		
	}
	static class GridHolder
	{
		ImageView imageview;
		CheckBox checkbox;
		int id;
	}

}
